package demo1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-04-05
 * Time: 14:53
 */
public class Test {
    public static void main(String[] args) {
        ArrayList<String> arrayList1 = new ArrayList<>();   //顺序表
        arrayList1.add("abc");
        arrayList1.add("def");

        List<String> list = new ArrayList<>();  //顺序表
        list.add("hello");

        list.addAll(arrayList1);
        //list.remove(1);
        //boolean ret = list.remove("hello");
        //list.clear();
        //System.out.println(arrayList1.add("hello"));


        System.out.println("====下标+for遍历====");         //使用下标+for遍历
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
        System.out.println("===foreach进行遍历打印===");         //利用foreach进行遍历打印
        for (String x:list) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("===迭代器进行打印===");         //利用迭代器进行打印
        Iterator<String> it = list.listIterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();
        System.out.println("===========");
    }
}
